/*
* @Author: dengjiayao
* @Date:   2017-04-19 13:25:50
* @Last Modified by:   dengjiayao
* @Last Modified time: 2017-04-28 14:48:07
*/
import Pages from '../../component/pages/pages.vue'
import { showMsg, getAIGuideList, updateAIGuide } from '../../vuex/action'

export default {
  name: 'ai-guide-list',
  components: {
    'vue-pages': Pages
  },
  vuex: {
    getters: {
      fresh: state => state.AIQuestionListNeedFresh
    },
    actions: {
      xShowMsg: showMsg,
      xGetList: getAIGuideList,
      xUpdate: updateAIGuide
    }
  },
  data() {
    return {
      list: []
    }
  },
  ready() {
    this.getList({})
  },
  methods: {
    getList() {
      this.xGetList({
        start: 0,
        limit: 100
      })
        .then((data) => {
          this.list = data.list
        })
        .catch((res) => {
          this.xShowMsg({
            type: 'danger',
            content: res.error_msg
          })
        })
    },
    updateItem(item) {
      var modal = this.$root.$refs.guideConfig
      modal.actionType = 'UPDATE'
      modal.form = {
        id: item.id,
        type: item.type,
        word: item.word,
        questionIds: item.questionIds
      }
      modal.showModal = true
    },
    deleteItem(id) {
      this.xUpdate({
        id: id,
        status: 0
      })
        .catch((res) => {
          this.xShowMsg({
            type: 'danger',
            content: res.error_msg
          })
        })
    }
  },
  watch: {
    fresh: function(v) {
      if (v) {
        this.getList({})
      }
    }
  }
}
